<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name=" apple-mobile-web-app-capable" />
    <!-- 隐藏状态栏  -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <!-- <title>登录</title> -->
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/details.css">
</head>

<body>
    <header>
        <div class="wrapper clearfix">
            <div class="login_fl fl">
                <a href="javascript:history.back();" class="login_icon"><img src="img/srh_icon.png" alt=""></a>
            </div>
            <div class="login_fr fr">
                <a href="javascript:goRegister()" class="register_btn">创建账号</a>
            </div>
            <h1 class="top_title">登录</h1>
        </div>
    </header>
    <article class="head_bg">
        <div class="head_pic"></div>
    </article>
    <article class="login p10 login_mod">
        <form action="">
            <input type="text" class="name" placeholder="手机号/昵称">
            <input type="password" class="password" placeholder="密码">
            <input type="button" class="debark" value="登录" onclick="doLogin()">
            <a href="javascript:(0);" onclick="forgetPsw()" class="pass-reglink fr">忘记密码？</a>
        </form>
    </article>
    <script src="js/jquery-1.11.2.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/constants.js"></script>
    <script src="js/common.js"></script>
    <script>
    var urlLogin = server_host + '/web/user/login.do';
    var urlGetUserinfo = server_host + '/userweb/getUserInfo.do';

    var params = getParameterByName('params');
    var fr = getParameterByName('fr');

    //默认来自包厢预订页面
    var url = 'confirm-order.html' + decodeURIComponent(atob(params));
    if (fr == 'pc') {
        //来自个人中心
        url = 'person-center.html';
    } else if (fr == 'orderfood') {
        //来自餐点确认页面
        url = 'order-food-confirm.html?params=' + params;
    } else if (fr == 'accountinfo') {
        url = 'index.html';
    }

    // 忘记密码
    function forgetPsw() {
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: urlGetUserinfo,
            success: function(data) {
                if (!data.isUserLogin) {
                    // alert(data.isUserLogin);
                    location.href = 're_password.html?isUserLogin=' + 0;
                }
            }
        });
    }

    // 登录
    function doLogin() {
        var mobileNum = $('input.name').val();
        var password = $('.password').val();
        if (mobileNum != '' && password != '') {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: urlLogin + '?phoneNum=' + mobileNum + '&passwd=' + password,
                success: function(data) {
                    if (data.isSuccess) {
                        $.ajax({
                            type: 'POST',
                            dataType: 'json',
                            url: urlGetUserinfo,
                            success: function(data) {
                                sessionStorage.setItem('userPhone', data.data.phone);
                                createCookie('CheerhiUserInfo', jsonObjToBase64({
                                    userName: mobileNum,
                                    password: password
                                }), 60);
                                location.href = url;
                            }
                        });
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            alert('用户名密码不能为空！')
        }
    }
    // 注册
    function goRegister() {
        location.href = 'register.html?params=' + params + '&fr=' + fr;
    }
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: urlGetUserinfo,
        success: function(data) {
            if (data.isUserLogin) {
                location.href = 'person-center.html';
            }
        }
    });
    </script>
</body>
<span style="display:none;"><script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1255764485'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s95.cnzz.com/z_stat.php%3Fid%3D1255764485%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));</script></span>
<script>
    _maq.push(['_setMaq', 'login']);
</script>
</html>
</html>
